package cocurrency.waitnotify;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created by luzl on 7/18/2017.
 */
public class MessageQueue {
    LinkedBlockingQueue<String> messageQueue=new LinkedBlockingQueue<String>();

    public synchronized void put(String message){
        try {
            messageQueue.put(message);
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized String get(){
        String message="";
        try {
            message= messageQueue.take();
            notify();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return message;
    }
}
